package cl.lexer.validator;

import java.util.ArrayList;
import java.util.List;

import cl.lexer.Token;
import cl.lexer.TokenType;

public class AssignmentOperatorValidator implements TokenValidator {
    
    private static List<String> operators;
    
    static {
        operators = new ArrayList<String>();
        
        operators.add("+=");
        operators.add("-=");
        operators.add("*=");
        operators.add("/=");
        operators.add("%=");
        operators.add("|=");
        operators.add("&=");
        
        operators.add("=");
    }
    
    @Override
    public TokenType getType() {
        return TokenType.ASSIGNMENT;
    }

    @Override
    public boolean isValid(String value) {
        for(String s : operators) {
            if(s.equals(value)) {
                return true;
            }
        }
        
        return false;
    }

    @Override
    public boolean possiblyValid(String value) {
        for(String s : operators) {
            if(s.indexOf(value) == 0) {
                return true;
            }
        }
        
        return false;
    }

    @Override
    public Token generateToken(String value) {
        return new Token(TokenType.ASSIGNMENT, value);
    }

}
